# -*- coding: utf-8 -*-

import cv2
import numpy as np
from skimage import morphology,data,color
import matplotlib.pyplot as plt
import utils


img = cv2.imread('output/img_row_14_score_cropped.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

# img_ro = morphology.remove_small_objects(gray,min_size=512, connectivity=1, in_place=False) 
# utils.show_gray_image(img_ro) 

thresh[thresh < 128] = 0
thresh[thresh >= 128] = 1
utils.show_gray_image(thresh)


img_sk = morphology.skeletonize(thresh)
utils.show_gray_image(img_sk) 

vertical_proj = np.sum(img_sk, axis=0)
plt.plot(range(vertical_proj.shape[0]), vertical_proj)
plt.gca()
plt.show()